<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>

<script src="../jquery-1.6.2.min.js" type="text/javascript"></script>
<link rel="stylesheet" href="../reset.css"/>
<style type="text/css">

</style>
<body>
<span id="top"></span>
<a href="#a1">as</a>

<div style="margin-top: 1000px;"></div>
<div id="a1" style="">asdf</div>
<a href="#a2">a2</a>

<div style="margin-top: 1000px;position: absolute;"></div>
<div style="margin-top: 1000px;"></div>
<div id="a2">a2</div>
<div style="margin-top: 1000px;"></div>

<script type="text/javascript">

    function logs() {
        var s = '';
        for (var i = 0,aLen = arguments.length; i < aLen; i++) {
            s += arguments[i] + ' ';
        }
        s = s.slice(0, -1);
        if (!window.console) alert(s);
        else
            console.log(s);
    }
    /**
     * .AnchorEx
     * @extends jquery.1.6.2
     * @fileOverview   文本框效果
     * @author 2kid
     * @email 444212235@qq.com
     * @site 2kid.org
     * @version 1.0
     * @date 2011-08-18
     * Copyright (c) 2011-2012 2kid
     * @example
     *   $.AnchorEx();
     */

    (function($) {

        $.fn.AnchorEx = function(options) {
            var opt = $.extend(true, {}, $.fn.AnchorEx.settings, options);
            return this.each(function() {
                var $this = $(this);
                var anchorEx = new AnchorEx(opt, $this);
                anchorEx.init();

            });
        }
        var AnchorEx = function(options, obj) {
            this.o = options;//默认参数
            this.time=this.o.time;
            this.targets=this.o.targets;

            this.$anchorEx = obj;

        }
        AnchorEx.prototype = {
            init:function(obj) {
                var _this = this;
                this.$anchorEx.bind('click', function() {
                    return  _this.goto();
                });
            },
            goto:function() {
                var id;
                if (this.targets == '') {
                    id = '' + this.$anchorEx.attr('href').match(/#\w+/);
                } else {
                    id = this.targets;
                }
                if ($(id).length) {
                    $('html,body').animate({scrollTop:$(id).position().top}, this.time);
                    return false;
                }
                return true;
            }

        }


        $.fn.AnchorEx.settings = {
            targets:'',
            time:1000
        }
    })(jQuery);
    $('<a href="#top"></a>').text('aa').appendTo('body');
    $('a[href^="#"]').AnchorEx();

</script>
</body>
</html>


